package c.j.a.d.b.j;

import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.text.TextUtils;
import c.j.a.c.y.a.i;
import c.j.a.d.b.b.g;
import c.j.a.d.b.d.d;
import c.j.a.d.b.d.h0;
import c.j.a.d.b.d.q;
import c.j.a.d.b.e.b;
import c.j.a.d.b.e.h;
import c.j.a.d.b.e.n;
import c.j.a.d.b.e.p;
import c.j.a.d.b.e.r;
import c.j.a.d.b.h.c;
import c.j.a.d.b.l.a;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/* compiled from: ProcessDownloadHandler */
public class v implements p {
    public final c a = b.B();
    public final n b = b.x();
    public final r c;
    public final boolean d;

    public v(boolean z) {
        if (z) {
            this.c = b.z();
        } else {
            this.c = b.y();
        }
        this.d = a.f.k("judge_service_alive", false);
    }

    public void A(boolean z, boolean z2) {
        r rVar = this.c;
        if (rVar != null) {
            c.j.a.d.b.e.a aVar = (c.j.a.d.b.e.a) rVar;
            WeakReference weakReference = aVar.a;
            if (weakReference != null && weakReference.get() != null) {
                String str = c.j.a.d.b.e.a.h;
                StringBuilder g = c.b.a.a.a.g("stopForeground  service = ");
                g.append(aVar.a.get());
                g.append(",  isServiceAlive = ");
                g.append(aVar.c);
                c.j.a.d.b.g.a.e(str, g.toString());
                try {
                    aVar.d = false;
                    ((Service) aVar.a.get()).stopForeground(z2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void B(int i) {
        c.j.a.d.b.g.a.a = i;
    }

    public boolean F(int i) {
        return this.b.f(i);
    }

    public boolean G(int i) {
        c cVar = this.a;
        boolean z = false;
        if (cVar == null) {
            return false;
        }
        synchronized (cVar) {
            c cVar2 = (c) cVar.d.get(i);
            if (cVar2 != null) {
                com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                if (cVar3 != null) {
                    if (cVar3.y()) {
                        cVar.h(cVar2, false);
                    }
                    z = true;
                }
            }
            com.ss.android.socialbase.downloader.g.c b = cVar.i.b(i);
            if (b != null && b.y()) {
                cVar2 = new c();
                cVar2.a = b;
                cVar.h(cVar2, false);
            }
        }
        return z;
    }

    public d K(int i) {
        c cVar = this.a;
        d dVar = null;
        if (cVar == null) {
            return null;
        }
        synchronized (cVar) {
            c cVar2 = (c) cVar.a.get(i);
            if (cVar2 != null) {
                dVar = cVar2.i;
            } else {
                cVar2 = (c) cVar.b.get(i);
                if (cVar2 != null) {
                    dVar = cVar2.i;
                } else {
                    cVar2 = (c) cVar.c.get(i);
                    if (cVar2 != null) {
                        dVar = cVar2.i;
                    } else {
                        cVar2 = (c) cVar.d.get(i);
                        if (cVar2 != null) {
                            dVar = cVar2.i;
                        } else {
                            c cVar3 = (c) cVar.e.get(i);
                            if (cVar3 != null) {
                                dVar = cVar3.i;
                            }
                        }
                    }
                }
            }
        }
        return dVar;
    }

    public void L(int i, boolean z) {
        c cVar = this.a;
        if (cVar != null) {
            c cVar2 = (c) cVar.a.get(i);
            if (cVar2 == null && i.s(65536)) {
                cVar2 = cVar.r(i);
            }
            if (cVar2 != null) {
                new h(cVar2, cVar.j).b(-4, null, true);
                com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                cVar.j.post(new b(cVar, cVar2.a(g.MAIN), cVar3, cVar2.a(g.NOTIFICATION)));
            }
            com.ss.android.socialbase.downloader.g.c b = cVar.i.b(i);
            if (i.s(65536)) {
                if (b != null) {
                    b.b0(-4);
                }
            } else if (b != null && i.x(b.o0())) {
                b.b0(-4);
            }
            cVar.l(i, z);
        }
    }

    public int M(int i) {
        return c.j.a.d.b.e.d.b().a(i);
    }

    /* JADX WARNING: Removed duplicated region for block: B:36:? A:{SYNTHETIC, RETURN} */
    /* JADX WARNING: Removed duplicated region for block: B:34:0x0053  */
    public c.j.a.d.b.d.j Q(int r3) {
        /*
        r2 = this;
        r0 = r2.a;
        if (r0 == 0) goto L_0x0050;
    L_0x0004:
        monitor-enter(r0);
        r1 = r0.a;	 Catch:{ all -> 0x004d }
        r1 = r1.get(r3);	 Catch:{ all -> 0x004d }
        r1 = (c.j.a.d.b.h.c) r1;	 Catch:{ all -> 0x004d }
        if (r1 == 0) goto L_0x0013;
    L_0x000f:
        r3 = r1.q;	 Catch:{ all -> 0x004d }
        monitor-exit(r0);
        goto L_0x0051;
    L_0x0013:
        r1 = r0.b;	 Catch:{ all -> 0x004d }
        r1 = r1.get(r3);	 Catch:{ all -> 0x004d }
        r1 = (c.j.a.d.b.h.c) r1;	 Catch:{ all -> 0x004d }
        if (r1 == 0) goto L_0x0021;
    L_0x001d:
        r3 = r1.q;	 Catch:{ all -> 0x004d }
        monitor-exit(r0);
        goto L_0x0051;
    L_0x0021:
        r1 = r0.c;	 Catch:{ all -> 0x004d }
        r1 = r1.get(r3);	 Catch:{ all -> 0x004d }
        r1 = (c.j.a.d.b.h.c) r1;	 Catch:{ all -> 0x004d }
        if (r1 == 0) goto L_0x002f;
    L_0x002b:
        r3 = r1.q;	 Catch:{ all -> 0x004d }
        monitor-exit(r0);
        goto L_0x0051;
    L_0x002f:
        r1 = r0.d;	 Catch:{ all -> 0x004d }
        r1 = r1.get(r3);	 Catch:{ all -> 0x004d }
        r1 = (c.j.a.d.b.h.c) r1;	 Catch:{ all -> 0x004d }
        if (r1 == 0) goto L_0x003d;
    L_0x0039:
        r3 = r1.q;	 Catch:{ all -> 0x004d }
        monitor-exit(r0);
        goto L_0x0051;
    L_0x003d:
        r1 = r0.e;	 Catch:{ all -> 0x004d }
        r3 = r1.get(r3);	 Catch:{ all -> 0x004d }
        r3 = (c.j.a.d.b.h.c) r3;	 Catch:{ all -> 0x004d }
        if (r3 == 0) goto L_0x004b;
    L_0x0047:
        r3 = r3.q;	 Catch:{ all -> 0x004d }
        monitor-exit(r0);
        goto L_0x0051;
    L_0x004b:
        monitor-exit(r0);
        goto L_0x0050;
    L_0x004d:
        r3 = move-exception;
        monitor-exit(r0);
        throw r3;
    L_0x0050:
        r3 = 0;
    L_0x0051:
        if (r3 != 0) goto L_0x0055;
    L_0x0053:
        r3 = c.j.a.d.b.e.b.e;
    L_0x0055:
        return r3;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.v.Q(int):c.j.a.d.b.d.j");
    }

    public void S(int i, boolean z) {
        c cVar = this.a;
        if (cVar != null) {
            cVar.l(i, z);
        }
    }

    public boolean T(int i) {
        return this.b.l(i);
    }

    public void U(List<String> list) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar) {
                try {
                    if (c.j.a.d.b.n.a.t(b.a())) {
                        for (int i = 0; i < cVar.a.size(); i++) {
                            c cVar2 = (c) cVar.a.get(cVar.a.keyAt(i));
                            if (cVar2 != null) {
                                com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                                if (cVar3 != null) {
                                    String str = cVar3.u;
                                    if (str != null && list.contains(str)) {
                                        if (cVar3.i() ? cVar3.h() : false) {
                                            cVar3.g0 = true;
                                            cVar3.i0 = true;
                                            cVar.g(cVar2);
                                            cVar3.G0 = true;
                                            Objects.requireNonNull(c.j.a.d.b.e.i.a(b.a()));
                                            Context context = b.a;
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            return;
        }
    }

    public void V(int i, Notification notification) {
        r rVar = this.c;
        if (rVar != null) {
            c.j.a.d.b.e.a aVar = (c.j.a.d.b.e.a) rVar;
            WeakReference weakReference = aVar.a;
            if (weakReference == null || weakReference.get() == null) {
                c.j.a.d.b.g.a.f(c.j.a.d.b.e.a.h, "startForeground: downloadService is null, do nothing!");
                return;
            }
            String str = c.j.a.d.b.e.a.h;
            StringBuilder h = c.b.a.a.a.h("startForeground  id = ", i, ", service = ");
            h.append(aVar.a.get());
            h.append(",  isServiceAlive = ");
            h.append(aVar.c);
            c.j.a.d.b.g.a.e(str, h.toString());
            try {
                ((Service) aVar.a.get()).startForeground(i, notification);
                aVar.d = true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void a(int i) {
        c cVar = this.a;
        if (cVar != null) {
            cVar.o(i);
        }
    }

    /* JADX WARNING: Missing block: B:12:0x001a, code skipped:
            if (r2.get(r4) != null) goto L_0x001c;
     */
    public boolean b(int r4) {
        /*
        r3 = this;
        r0 = r3.a;
        r1 = 0;
        if (r0 == 0) goto L_0x0022;
    L_0x0005:
        monitor-enter(r0);
        if (r4 == 0) goto L_0x0021;
    L_0x0008:
        r2 = r0.a;	 Catch:{ all -> 0x001e }
        if (r2 == 0) goto L_0x0012;
    L_0x000c:
        r2 = r2.get(r4);	 Catch:{ all -> 0x001e }
        if (r2 != 0) goto L_0x001c;
    L_0x0012:
        r2 = r0.c;	 Catch:{ all -> 0x001e }
        if (r2 == 0) goto L_0x0021;
    L_0x0016:
        r4 = r2.get(r4);	 Catch:{ all -> 0x001e }
        if (r4 == 0) goto L_0x0021;
    L_0x001c:
        r1 = 1;
        goto L_0x0021;
    L_0x001e:
        r4 = move-exception;
        monitor-exit(r0);
        throw r4;
    L_0x0021:
        monitor-exit(r0);
    L_0x0022:
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.d.b.j.v.b(int):boolean");
    }

    public boolean c() {
        boolean z;
        Context context = b.a;
        synchronized (b.class) {
            z = b.L;
        }
        return z;
    }

    public void d() {
    }

    public void d(int i) {
        c cVar = this.a;
        if (cVar != null) {
            cVar.p(i);
        }
    }

    public boolean e(int i) {
        c cVar = this.a;
        return cVar != null ? cVar.j(i) : false;
    }

    public int f(int i) {
        c cVar = this.a;
        if (cVar == null) {
            return 0;
        }
        com.ss.android.socialbase.downloader.g.c n = cVar.n(i);
        if (n == null) {
            return 0;
        }
        return n.o0();
    }

    public com.ss.android.socialbase.downloader.g.c g(int i) {
        c cVar = this.a;
        return cVar != null ? cVar.n(i) : null;
    }

    public List<com.ss.android.socialbase.downloader.g.b> h(int i) {
        return this.b.c(i);
    }

    public void i(int i, List<com.ss.android.socialbase.downloader.g.b> list) {
        this.b.i(i, list);
    }

    public List<com.ss.android.socialbase.downloader.g.c> j(String str) {
        n nVar = this.b;
        return nVar != null ? nVar.j(str) : null;
    }

    public void k(int i, int i2, long j) {
        this.b.k(i, i2, j);
    }

    public long l(int i) {
        n nVar = this.b;
        if (nVar == null) {
            return 0;
        }
        com.ss.android.socialbase.downloader.g.c b = nVar.b(i);
        if (b == null) {
            return 0;
        }
        int i2 = b.R;
        if (i2 <= 1) {
            return b.I();
        }
        List c = this.b.c(i);
        if (c == null || c.size() != i2) {
            return 0;
        }
        return c.j.a.d.b.n.a.y(c);
    }

    public void m(int i, int i2, int i3, long j) {
        this.b.m(i, i2, i3, j);
    }

    public void n(int i, int i2, int i3, int i4) {
        this.b.n(i, i2, i3, i4);
    }

    public void o(int i) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar) {
                c cVar2 = (c) cVar.a.get(i);
                if (cVar2 != null) {
                    com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                    if (cVar3 != null) {
                        cVar3.N = true;
                        cVar.g(cVar2);
                    }
                }
            }
        }
    }

    public void p(int i, boolean z) {
        c.j.a.d.b.e.d.b().d(i, z);
    }

    public void q(int i, d dVar) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar.a) {
                c cVar2 = (c) cVar.a.get(i);
                if (cVar2 != null) {
                    cVar2.i = dVar;
                }
            }
        }
    }

    public void r(int i, int i2, c.j.a.d.b.d.b bVar, g gVar, boolean z, boolean z2) {
        c cVar = this.a;
        if (cVar != null) {
            cVar.c(i, i2, bVar, gVar, z, z2);
        }
    }

    public void s(int i, int i2, c.j.a.d.b.d.b bVar, g gVar, boolean z) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar) {
                cVar.c(i, i2, bVar, gVar, z, true);
            }
        }
    }

    public com.ss.android.socialbase.downloader.g.c t(String str, String str2) {
        return g(b.c(str, str2));
    }

    public void u(c.j.a.d.b.d.n nVar) {
        Context context = b.a;
        if (nVar != null) {
            synchronized (b.A) {
                b.A.add(nVar);
            }
        }
    }

    public List<com.ss.android.socialbase.downloader.g.c> v(String str) {
        c cVar = this.a;
        if (cVar == null) {
            return null;
        }
        Objects.requireNonNull(cVar);
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (Integer intValue : cVar.a()) {
            com.ss.android.socialbase.downloader.g.c n = cVar.n(intValue.intValue());
            if (n != null && str.equals(n.u)) {
                arrayList.add(n);
            }
        }
        return arrayList;
    }

    public h0 w(int i) {
        c cVar = this.a;
        h0 h0Var = null;
        if (cVar == null) {
            return null;
        }
        synchronized (cVar) {
            c cVar2 = (c) cVar.a.get(i);
            if (cVar2 != null) {
                h0Var = cVar2.s;
            } else {
                cVar2 = (c) cVar.b.get(i);
                if (cVar2 != null) {
                    h0Var = cVar2.s;
                } else {
                    cVar2 = (c) cVar.c.get(i);
                    if (cVar2 != null) {
                        h0Var = cVar2.s;
                    } else {
                        cVar2 = (c) cVar.d.get(i);
                        if (cVar2 != null) {
                            h0Var = cVar2.s;
                        } else {
                            c cVar3 = (c) cVar.e.get(i);
                            if (cVar3 != null) {
                                h0Var = cVar3.s;
                            }
                        }
                    }
                }
            }
        }
        return h0Var;
    }

    public void x(c cVar) {
        r rVar = this.c;
        if (rVar != null) {
            rVar.a(cVar);
        } else if (cVar != null) {
            q qVar = cVar.l;
            com.ss.android.socialbase.downloader.g.c cVar2 = cVar.a;
            com.ss.android.socialbase.downloader.e.a aVar = new com.ss.android.socialbase.downloader.e.a(1003, "downloadServiceHandler is null");
            com.ss.android.socialbase.downloader.g.c cVar3 = cVar.a;
            i.n(qVar, cVar2, aVar, cVar3 != null ? cVar3.o0() : 0);
        }
    }

    public void y(int i) {
        this.b.d(i);
    }

    public void z(int i, int i2, c.j.a.d.b.d.b bVar, g gVar, boolean z) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar) {
                c r = cVar.r(i);
                if (r == null) {
                    r = (c) cVar.f.get(Integer.valueOf(i));
                }
                if (r != null) {
                    r.c(i2, bVar, gVar, z);
                }
            }
        }
    }

    public void a() {
        c cVar = this.a;
        if (cVar != null) {
            List<Integer> a = cVar.a();
            if (a != null) {
                for (Integer intValue : a) {
                    cVar.o(intValue.intValue());
                }
            }
        }
    }

    public void c(int i) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar) {
                c cVar2 = (c) cVar.a.get(i);
                if (cVar2 != null) {
                    com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                    if (cVar3 != null) {
                        cVar3.G0 = false;
                    }
                    cVar.g(cVar2);
                } else {
                    cVar.p(i);
                }
            }
        }
    }

    public void d(int i, List<com.ss.android.socialbase.downloader.g.b> list) {
        this.b.d(i, list);
    }

    public boolean e() {
        return this.b.c();
    }

    public boolean g() {
        if (!this.d) {
            return false;
        }
        r rVar = this.c;
        if (rVar == null || !((c.j.a.d.b.e.a) rVar).c) {
            return false;
        }
        return true;
    }

    public List<com.ss.android.socialbase.downloader.g.c> b(String str) {
        n nVar = this.b;
        return nVar != null ? nVar.b(str) : null;
    }

    public void f(com.ss.android.socialbase.downloader.g.b bVar) {
        this.b.f(bVar);
    }

    public void f() {
        this.b.b();
    }

    public boolean b() {
        r rVar = this.c;
        if (rVar == null) {
            return false;
        }
        c.j.a.d.b.e.a aVar = (c.j.a.d.b.e.a) rVar;
        Objects.requireNonNull(aVar);
        String str = c.j.a.d.b.e.a.h;
        StringBuilder g = c.b.a.a.a.g("isServiceForeground = ");
        g.append(aVar.d);
        c.j.a.d.b.g.a.e(str, g.toString());
        return aVar.d;
    }

    public void a(List<String> list) {
        c cVar = this.a;
        if (cVar != null) {
            synchronized (cVar) {
                try {
                    boolean t = i.s(1048576) ? c.j.a.d.b.n.a.t(b.a()) : true;
                    for (int i = 0; i < cVar.c.size(); i++) {
                        c cVar2 = (c) cVar.c.get(cVar.c.keyAt(i));
                        if (cVar2 != null) {
                            com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                            if (cVar3 != null) {
                                String str = cVar3.u;
                                if (str != null && list.contains(str)) {
                                    if (!cVar3.g || t) {
                                        cVar3.g0 = true;
                                        cVar3.i0 = true;
                                        cVar.g(cVar2);
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return;
        }
        return;
    }

    public void b(com.ss.android.socialbase.downloader.g.c cVar) {
        this.b.b(cVar);
    }

    public List<com.ss.android.socialbase.downloader.g.c> c(String str) {
        n nVar = this.b;
        return nVar != null ? nVar.c(str) : null;
    }

    public boolean c(com.ss.android.socialbase.downloader.g.c cVar) {
        return this.b.a(cVar);
    }

    public List<com.ss.android.socialbase.downloader.g.c> a(String str) {
        c cVar = this.a;
        List<com.ss.android.socialbase.downloader.g.c> list = null;
        if (cVar == null) {
            return null;
        }
        Objects.requireNonNull(cVar);
        if (!TextUtils.isEmpty(str)) {
            list = cVar.i.a(str);
            if (list == null || list.isEmpty()) {
                synchronized (cVar.a) {
                    list = new ArrayList();
                    int size = cVar.a.size();
                    for (int i = 0; i < size; i++) {
                        c cVar2 = (c) cVar.a.valueAt(i);
                        if (cVar2 != null) {
                            com.ss.android.socialbase.downloader.g.c cVar3 = cVar2.a;
                            if (cVar3 != null && str.equals(cVar3.d)) {
                                list.add(cVar2.a);
                            }
                        }
                    }
                }
            }
        }
        return list;
    }

    public int a(String str, String str2) {
        return b.c(str, str2);
    }

    public boolean a(com.ss.android.socialbase.downloader.g.c cVar) {
        boolean z = false;
        if (cVar == null) {
            return false;
        }
        int o0 = cVar.o0();
        String str = cVar.e;
        String str2 = cVar.b;
        String str3 = c.j.a.d.b.n.a.a;
        if (o0 == -3 && !c.j.a.d.b.n.a.R(str, str2)) {
            z = true;
        }
        if (z) {
            if (i.s(33554432)) {
                S(cVar.g0(), true);
            } else {
                int g0 = cVar.g0();
                c cVar2 = this.a;
                if (cVar2 != null) {
                    com.ss.android.socialbase.downloader.g.c b = cVar2.i.b(g0);
                    if (b != null) {
                        cVar2.f(b);
                    }
                    cVar2.j.post(new d(cVar2, g0));
                    b.k(new e(cVar2, g0, true), true);
                }
            }
        }
        return z;
    }

    public void a(c cVar) {
        r rVar = this.c;
        if (rVar != null) {
            rVar.b(cVar);
        }
    }

    public void a(int i, int i2) {
        List list;
        synchronized (b.A) {
            list = b.A;
        }
        if (list != null) {
            synchronized (b.A) {
                List<c.j.a.d.b.d.n> list2 = b.A;
            }
            for (c.j.a.d.b.d.n nVar : list2) {
                if (nVar != null) {
                    nVar.a(i2, i);
                }
            }
        }
    }

    public void a(int i, long j) {
        c cVar = this.a;
        if (cVar != null) {
            com.ss.android.socialbase.downloader.g.c b = cVar.i.b(i);
            if (b != null) {
                b.u0 = j;
            }
            cVar.d(i, j);
        }
    }
}
